#include <dlfcn.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
void* dyld_handle=0;//dyld sets this handle
void* libc_handle=0;
#include "debug_logger.h"



void dyld_bootstrap(void* handle)
{
	DYLD_DEBUG(printf("init dyld in libsystem\n"));
	//exports dyld apis to all cocotron components
	dyld_handle=handle;
	libc_handle=dlopen("libc.so",RTLD_LAZY);
}

void* dyld_getsymbol(char* sym)
{
	
	int pos = strcspn(sym,"$");
	if(pos!=strlen(sym))
	{
		char dest[pos];
		memcpy(dest,sym+1,pos-1);
		dest[pos-1]=0;
		
		return dlsym(libc_handle,dest);
	}
	if(strcmp("___stderrp",sym)==0) return &stderr;
	return 0;
}


